package com.example.datastructures.util;

import com.example.datastructures.LinkedListNode;

public class LinkedListUtil {
	public static void insertNode(LinkedListNode node, int value){
		if (node != null){
			
			if (node.getNextNode() == null){
				node.setNextNode(new LinkedListNode(value, null));
			} else {
				insertNode(node.getNextNode(), value);
			}
		}
	}
	
	public static void insertNodeA(LinkedListNode node, int value){
		LinkedListNode nextNode = null;
		
		for (; (nextNode = node.getNextNode()) != null; ){
			
			if (nextNode.getNextNode() == null){
				nextNode.setNextNode(new LinkedListNode(value, null));
			}
		}
	}
	
	public static void printNodes(LinkedListNode node){
		
		for (; node != null; ){
			
			System.out.println(node.getValue());
			
			node = node.getNextNode();
		}
	}
	
	public static void main(String... args){
		LinkedListNode node = null;
		
		node = new LinkedListNode(10, null);
		
		insertNode(node, 19);
		insertNode(node, 14);
		insertNode(node, 12);
		insertNode(node, 14);
		insertNode(node, 15);
		
		printNodes(node);
	}
}